<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>添加品牌</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__STATIC__/admin/static/css/font.css">
		<link rel="stylesheet" href="__STATIC__/admin/static/css/weadmin.css">
    <script type="text/javascript" src='__STATIC__/admin/static/js/jquery3.2.1.min.js'></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>    
      #X{
        position: relative;
        top: -40px;
        left:-18px;
        color:red;
        font-size: 25px;
        background: white;
        border-radius: 30px;
      }

    </style>
  </head>
  
  <body>
    <div class="weadmin-body">
        <form class="layui-form">
          <span class="test"></span>
          <input type="hidden" name='img' value=".{$info[0]['logo']}"/>
          <input type="hidden" name='bid' value="{$info[0]['bid']}"/>
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="we-red">*</span>品牌名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="username" name="bname" required="" lay-verify="required"
                  autocomplete="off" class="layui-input" value="{$info[0]['bname']}">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="we-red">*</span>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="first" class="layui-form-label">
                  <span class="we-red">*</span>大写首字母
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="first" name="first" required="" lay-verify="required" autocomplete="off" class="layui-input" value="{$info[0]['first']}" readonly>
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="we-red">*</span>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="logo" class="layui-form-label">
                  图标
              </label>
              <div class="layui-input-inline">
                  <button type="button" class="layui-btn layui-btn-primary" id="logo" style="height:100px;width:100px;border-radius: 10px;">
                    {if $info[0]['logo'] != ''}
                    <img src="{$info[0]['logo']}" alt='' style='height:100px;width:100px;margin-left: -19px;border-radius: 10px;' class='preview'>
                    {else/}
                    <i class='layui-icon' style='font-size:80px;margin-left: -8px;'>&#xe654;</i>
                    {/if}
                  </button>
                  <a href="javascript:;" class="xdel" 
                    {if $info[0]['logo'] != ''}
                     
                    {else/}
                    style="display: none"
                    {/if}><i class="layui-icon" id="X">&#x1007;</i></a>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="phone" class="layui-form-label">
                  是否推荐
              </label>
              <div class="layui-input-inline">
                  <input type="checkbox" name="iscom" lay-skin="switch" lay-text="推荐|不推荐" {if $info[0]['is_commend']==1}checked{/if}>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label"></label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">修改</button>
          </div>
      </form>
    </div>
		<script src="__STATIC__/admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript">
    		layui.extend({
					admin: '{/}__STATIC__/admin/static/js/admin'
				});
        layui.use(['form','layer','admin','upload'], function(){
          var form = layui.form,
          	admin = layui.admin,
          	layer = layui.layer;
            upload = layui.upload;
          	form.render();
          //监听提交
          form.on('submit(add)', function(data){
            $.ajax({
                type: 'POST',
                url: "{:url('admin/car/brandedit')}",
                data:$('form').serialize(),
                traditional:true,
                success: function(data){
                    if(data.code==1){
                      layer.msg(data.msg,{icon:1,time:1000},function(){
                          parent.location.reload();
                          parent.layer.close();
                      });
                    }else{
                      layer.msg(data.msg,{icon:2,time:1000},function(){

                      });
                    }
                }
            });
            return false;
          });
          //执行实例
            var uploadInst = upload.render({
              elem: '#logo' //绑定元素
              ,url: "{:url('admin/car/brandedit')}" //上传接口
              ,field:"image"
              ,data:{
                img: function(){
                  return $("input[name='img']").val();
                },
                bid:{$info[0]['bid']},
              }
              ,done: function(res){
                //上传完毕回调
                img = "<img src='"+res.im+"' alt='' style='height:100px;width:100px;margin-left: -19px;border-radius: 10px;' class='preview'>"
                $("input[name='img']").val(res.path);
                $("#logo").html(img);
                $(".xdel").css('display','');
              }
              ,error: function(){
                //请求异常回调
              }
            });
            //取消预览图片
            $(".xdel").click(function(){
              $.ajax({
                type: 'POST',
                url: "{:url('admin/car/brandedit')}",
                data:"delim="+$(".preview").attr('src')+"&bid="+{$info[0]['bid']},
                success: function(data){
                  $(".xdel").css('display','none');
                  $("#logo").html("<i class='layui-icon' style='font-size:80px;margin-left: -8px;'>&#xe654;</i>");
                  $("input[name='img']").val("");
                }
              });
            })
        });
    </script>
  </body>

</html>


